package PAT;

import java.util.Scanner;

public class PAT1045 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] colorIndex = new int[201];
        for (int i = 0; i < n; i++) {
            colorIndex[scanner.nextInt()] = i;
        }
        scanner.nextLine();
        int i1 = scanner.nextInt();
        String s = scanner.nextLine();
        String[] s1 = s.split(" ");
        int ans = 1<<31;
        int length = s1.length;
        int[] dp = new int[length]; //dp[i] 表示values[0:i]的最大递增数
        for (int i = 0; i < length; i++) { // 往后加一个遍历一遍
            dp[i] = 1;
            for (int j = 0; j < i; j++) {
                if (colorIndex[Integer.parseInt(s1[j])] <= colorIndex[Integer.parseInt(s1[i])] && dp[i] < dp[j] + 1) {
                    dp[i] = dp[j]+1;
                }
            }
            ans = Math.max(ans,dp[i]);
        }
        System.out.println(ans);
    }
}
